import { createRouter, createWebHistory } from "vue-router";

import CatMain from "@/views/CatMain.vue";
import TravelQuery from "@/views/TravelQuery.vue";
import { getLogin } from "@/api";
import { getToken } from "@/utils/token";
import ComplaintRanking from "@/views/ComplaintRanking.vue";
import Complaints from "@/views/complaints.vue";

import MobileLogin from "@/views/mobile/MobileLogin.vue";
import PersonalPage from "@/views/mobile/PersonalPage.vue";
import ComplaintApplication from "@/views/ComplaintApplication.vue";
import BottomNav from "@/components/BottomNav.vue";
import CompanyHome from "@/views/CompanyHome.vue";
import RegisterPage from "@/views/mobile/RegisterPage.vue";
import ComplaintDetails from "@/views/ComplaintDetails.vue";
import ForgetPassword from "@/views/mobile/ForgetPassword.vue";


BottomNav;
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      name: "login",
      path: "/login",
      component: MobileLogin,
    },
    {
      path: "/",
      redirect: "login",
    },
    {
      name: "personal",
      path: "/personal",
      component: PersonalPage,
      meta: { requiresAuth: true }, // 标记为需要登录的路由
    },
    {
      name: "complaintranking",
      path: "/complaintranking",
      component: ComplaintRanking,
    },
    {
      name: "complaints",
      path: "/complaints",
      component: Complaints,
    },
    {
      name: "complaintApplication",
      path: "/ComplaintApplication",
      component: ComplaintApplication,
    },
    {
      name: "main",
      path: "/main",
      component: CatMain,
    },
    {
      name:"complaintDetail",
      path:"/complaintDetail/:cId",
      component:ComplaintDetails
    },
    {
      path: '/travel-query',
      name: 'TravelQuery',
      component: TravelQuery
    },
    // router/index.js
    {
      path: "/companyHome/:id",
      name: "companyHome",
      component: () => import("@/views/CompanyHome.vue"), // 建议懒加载
      props: true,
    },
      // 新增注册页路由
  {
    path: '/register',
    name: 'Register',
    component: RegisterPage,
    meta: { requiresAuth: false }//标记无需登录
  },
  //新增忘记密码页路由
  {
    path: '/forgot-password',
    name: 'ForgotPassword',
    component: ForgetPassword,
    meta: { requiresAuth: false }
  },
  ],
});

//全局前置路由守卫
// router.beforeEach((to, from, next) => {
//   const token = getToken();
//   if (token) {
//     if (to.path == "/login" || to.path == "/reg") {
//       next({ path: "/" });
//     } else {
//       next();
//     }
//   } else {
//     next();
//   }
// });

export default router;
